# lobby.py

import grpc
import rank_pb2, rank_pb2_grpc


def add_player(stub, name, score):
    player = rank_pb2.Player(name=name, score=score)
    response = stub.AddPlayer(player)
    print("Added player:", response)


def get_player_rank(stub, player_name):
    request = rank_pb2.GetPlayerRankRequest(player_name=player_name)
    response = stub.GetPlayerRank(request)
    print("Player rank:", response.rank)


def list_top_players(stub, count):
    request = rank_pb2.ListTopPlayersRequest(count=count)
    responses = stub.ListTopPlayers(request)
    for response in responses:
        print("Top player:", response)


def main():
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = rank_pb2_grpc.RankServiceStub(channel)
        add_player(stub, "Alice", 100)
        get_player_rank(stub, "Alice")
        list_top_players(stub, 10)


if __name__ == '__main__':
    main()
